package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "护理等级管理")
@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelController extends BaseController {

    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 查询全部护理等级信息
     *
     * @return
     */
    @ApiOperation(value = "查询所有护理等级信息")
    @GetMapping("listAll")
    public ResponseResult<List<NursingLevelVo>> queryAllNursingLevel() {
        List<NursingLevelVo> list = nursingLevelService.queryAllNursingLevel();
        return success(list);
    }

    /**
     * 新增护理计划
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "新增护理计划")
    @PostMapping("insert")
    public ResponseResult addNursingLevel(@ApiParam(value = "新增护理dto对象", required = true)
                                          @RequestBody NursingLevelDto dto) {
        nursingLevelService.addNursingLevel(dto);
        return success();
    }

    /**
     * 分页条件查询
     *
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @ApiOperation(value = "分页条件查询护理计划")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> pageQuery(
            @ApiParam(value = "姓名条件")
            String name,
            @RequestParam(required = false, defaultValue = "1")
            @ApiParam(value = "当前页码", required = true)
            Integer pageNum,
            @ApiParam(value = "每页大小", required = true)
            @RequestParam(required = false, defaultValue = "10")
            Integer pageSize,
            @ApiParam(value = "状态条件")
            Integer status) {
        PageResponse<NursingLevelVo> vo = nursingLevelService.pageQuery(name, pageNum, pageSize, status);
        return success(vo);
    }

    @ApiOperation(value = "根据Id查询")
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> queryById(@PathVariable Integer id) {
        NursingLevelVo vo = nursingLevelService.queryById(id);
        return success(vo);
    }

    /**
     * 修改护理等级
     *
     * @param vo
     * @return
     */
    @ApiOperation(value = "修改护理等级")
    @PutMapping("update")
    public ResponseResult updateNursingLevel(@RequestBody NursingLevelVo vo) {

        nursingLevelService.updateNursingLevel(vo);
        return success();
    }

    /**
     * 删除狐狸等级
     */

    @ApiOperation("删除护理等级")
    @DeleteMapping("delete/{id}")
    public ResponseResult deleteById(@PathVariable Integer id) {
        nursingLevelService.deleteById(id);
        return success();
    }

    /**
     * 启用禁用
     */
    @ApiOperation("启用禁用修改")
    @PutMapping("{id}/status/{status}")
    public ResponseResult updateStatus(@ApiParam(value = "护理等级Id", required = true)
                                       @PathVariable Integer id,
                                       @ApiParam(value = "要修改后的状态", required = true)
                                       @PathVariable Integer status) {

            nursingLevelService.updateStatus(id,status);
        return success();
    }


}
